import 'dart:convert';

import '../helper/Helper.dart';

import '../helper/dioHelper.dart';

class ScqxR {
  int ID;
  double lat;
  double lng;
  double pr1;
  double pr3;
  double pr6;
  double pr12;
  double pr24;
  double pr36;
  double pr48;
  double pr60;
  double pr72;
  String? sid;
  String? sname;
  String? st;

  ScqxR(
      this.ID,
      this.lat,
      this.lng,
      this.pr1,
      this.pr3,
      this.pr6,
      this.pr12,
      this.pr24,
      this.pr36,
      this.pr48,
      this.pr60,
      this.pr72,
      this.sid,
      this.sname,
      this.st);
  ScqxR.fromJson(Map<String, dynamic> json)
      : ID = 0,
        lat = Helper.GetDouble(json["lat"]),
        lng = Helper.GetDouble(json["lng"]),
        pr1 = Helper.GetDouble(json["pr1"]),
        pr3 = Helper.GetDouble(json["pr3"]),
        pr6 = Helper.GetDouble(json["pr6"]),
        pr12 = Helper.GetDouble(json["pr12"]),
        pr24 = Helper.GetDouble(json["pr24"]),
        pr36 = Helper.GetDouble(json["pr36"]),
        pr48 = Helper.GetDouble(json["pr48"]),
        pr60 = Helper.GetDouble(json["pr60"]),
        pr72 = Helper.GetDouble(json["pr72"]),
        sid = json["sid"],
        sname = json["sname"],
        st = json["st"];
  Map<String, dynamic> toJson() => {
        'ID': ID,
        'lat': lat,
        'lng': lng,
        'pr1': pr1,
        'pr3': pr3,
        'pr6': pr6,
        'pr12': pr12,
        'pr24': pr24,
        'pr36': pr36,
        'pr48': pr48,
        'pr60': pr60,
        'pr72': pr72,
        'sid': sid,
        'sname': sname,
        'st': st,
      };
  static Future<bool> Add(ScqxR x1) async {
    var response = await DioHelper.Post("/ScqxR/Add", x1.toJson());
    if (response.statusCode == 200) return true;
    return false;
  }

  static Future<bool> Update(ScqxR x1) async {
    var response = await DioHelper.Post("/ScqxR/Update", x1.toJson());
    if (response.statusCode == 200) return true;
    return false;
  }

  static Future<bool> Delete(ScqxR x1) async {
    var st = x1.toJson();
    var response = await DioHelper.Post("/ScqxR/Delete", x1.toJson());
    if (response.statusCode == 200) return true;
    return false;
  }

  static Future<ScqxR?> Get(String where, dynamic data) async {
    var response = await DioHelper.Post("/ScqxR/GetByWhere", {
      "Where": where,
      "obj": data,
    });

    if (response.statusCode == 200) return new ScqxR.fromJson(response.data);
    return null;
  }

  static Future<List<ScqxR>> GetList(
      String where, dynamic data, int pageIndex, int pageSize) async {
    var response = await DioHelper.Post("/ScqxR/GetListByWhere", {
      "Where": where,
      "obj": data,
      "PageIndex": pageIndex,
      "PageSize": pageSize,
    });
    var list1 = <ScqxR>[];
    if (response.statusCode == 200) {
      for (var x in response.data) {
        list1.add(new ScqxR.fromJson(x));
      }
    }
    return list1;
  }

  static Future<List<ScqxR>> GetAllList() async {
    print('ScqxR GetAllList');

    // var response = await DioHelper.Get2(
    //     "http://dj.scqx.net:10123", "/zpp/ds?key=SidprTable", {});

    var response =
        await DioHelper.Get3("http://dj.scqx.net:10123/zpp/ds?key=SidprTable");

    print(response.data);
    Map<String, dynamic> list2 = jsonDecode(response.data);

    // print(list2["cdata"]);
    var list1 = <ScqxR>[];

    if (response.statusCode == 200) {
      for (var x in list2["cdata"]) {
        list1.add(new ScqxR.fromJson(x));
      }
    }
    return list1;
  }
}
